import { defineStore } from 'pinia'

let _userInfoCache = sessionStorage.getItem('pinia-userinfo') || "{}"
_userInfoCache = JSON.parse(_userInfoCache)
let userInfo = _userInfoCache
export const useCounterStore = defineStore('useCounterStore', {
      state(){
         return {
            users:{
               "id": "",
               "name": "",
               "password": "",
               "photo": [],
               "sex": "男",
               "address": "",
               "birthday": "",
               "phone": "",
               
            },
            userInfo,
            searchInput:[]
         }
      },
      actions:{
       setUsers(newUsers){
         localStorage.setItem('usersToken',JSON.stringify(newUsers))
         this.users= newUsers
       },
       setUserInfo(_newUserInfo) {
         this.userInfo = _newUserInfo
         sessionStorage.setItem('pinia-userinfo', JSON.stringify(_newUserInfo))
     },
     setSearchInput(searchInput){
      this.searchInput.push(searchInput)
      
     }
       
      },
      getters:{
         usersVal(){
            return this.users
         },
         getSearchInput(){
            return this.searchInput
         }
      },

      // 持久化存储
      persist:{
         enabled:true,
         strategies:[
            {
               key:'searchInput',  // key的名称
               storage:localStorage,  // 存储方式
               paths:['searchInput']  // 存储内容

            }
         ]
      }
   }
)
